Option Explicit On
Option Strict On

Imports System
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Security
Imports Microsoft.SharePoint.Administration

''' <summary>
''' This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
''' </summary>
''' <remarks>
''' The GUID attached to this class may be used during packaging and should not be modified.
''' </remarks>

<GuidAttribute("9931ee8b-24ae-4521-9236-994a45c5549f")> _
Public Class BengenImportTimerJobEventReceiver
    Inherits SPFeatureReceiver

    ' Uncomment the method below to handle the event raised after a feature has been activated.

    Public Overrides Sub FeatureActivated(ByVal properties As SPFeatureReceiverProperties)
        Dim site As SPSite = CType(properties.Feature.Parent, SPSite)


        Dim job = New ImportDataTimerJob(ImportDataTimerJob.JOB_NAME, site.WebApplication)
        'Dim sch As New SPMinuteSchedule
        'sch.BeginSecond = 0
        'sch.EndSecond = 10
        'sch.Interval = 2
        'job.Schedule = sch
        Dim sch As New SPHourlySchedule
        sch.BeginMinute = 0
        sch.EndMinute = 5
        job.Schedule = sch
        job.Update()
    End Sub


    ' Uncomment the method below to handle the event raised before a feature is deactivated.

    Public Overrides Sub FeatureDeactivating(ByVal properties As SPFeatureReceiverProperties)
        Dim site As SPSite = CType(properties.Feature.Parent, SPSite)

        For Each job In site.WebApplication.JobDefinitions
            If job.Name.Equals(ImportDataTimerJob.JOB_NAME, StringComparison.OrdinalIgnoreCase) Then
                job.Delete()
            End If
        Next
    End Sub


    ' Uncomment the method below to handle the event raised after a feature has been installed.

    'Public Overrides Sub FeatureInstalled(ByVal properties As SPFeatureReceiverProperties)
    'End Sub


    ' Uncomment the method below to handle the event raised before a feature is uninstalled.

    'Public Overrides Sub FeatureUninstalling(ByVal properties As SPFeatureReceiverProperties)
    'End Sub

    ' Uncomment the method below to handle the event raised when a feature is upgrading.

    'Public Overrides Sub FeatureUpgrading(ByVal properties As Microsoft.SharePoint.SPFeatureReceiverProperties, ByVal upgradeActionName As String, ByVal parameters As System.Collections.Generic.IDictionary(Of String, String))
    'End Sub

End Class
